home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: reversing a string
- Date: Fri, 12 Apr 96 12:20:53 GMT
- Organization: none
- Message-ID: <829311653snz@genesis.demon.co.uk>
- References: <4k6cjl$j8f@central.server.swt.edu> <4k6jks$fh9@solutions.solon.com> <DpLtt5.Lqu@iquest.net> <829135845snz@genesis.demon.co.uk> <DpnFtK.C1w@iquest.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <DpnFtK.C1w@iquest.net> dlmiller@iquest.net "Doug Miller" writes:
-
- >Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
- >>In article <DpLtt5.Lqu@iquest.net> dlmiller@iquest.net "Doug Miller" writes:
- >>
- >>>seebs@solutions.solon.com (Peter Seebach) wrote:
- >>>>I can't see a way to reverse in place without a temporary of some sort,
- >>>>or a loop of some sort, or something which is fundementally equivalent
- >>>>to one of those. There may be one, but I don't know it.
- >>>>
- >>>>-s
- >>>
- >>>How about this:
- >>>
- >>>void swap (char *s) {
- >>> if (strlen(s) > 1) {
- >>
- >>strlen() is fundamentally based on a loop.
- >
- >OK, since the objective is to determine if the string is more than 1 character
- > long, we can do
- >the same by testing the next character.
- >Replace
- > if (strlen(s) > 1)
- >with
- > if (*(s + 1))
- >and the rest of the algorithm is still valid.
-
- OK, you can do that with this particular strlen() but there are several
- others in the function that can't be replaced in this way since they are
- used to reference characters at the end of the string.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-